<%@ page language="java" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript"
	src="http://code.jquery.com/jquery-1.10.2.min.js">
	
</script>
<script type="text/javascript">

	var generateHideElement = function(name, value) {
		var tempInput = document.createElement("input");
		tempInput.type = "hidden";
		tempInput.name = name;
		tempInput.value = value;
		return tempInput;
	}

	function saveItem(e) {
		var nm = '';
		var tp = '';
		var mrk = '';
		var amtJpy = '';
		var amtRmb = '';
		var amtSell = '';

		var tr = $("#" + e);
		var tds = [];
		tds = tr[0].getElementsByTagName("td");
		for (var j = 0; j < tds.length - 2; j++) {
			var input = tds[j].getElementsByTagName("input");
			if ("theNm" == input[0].name) {
				nm = input[0].value;
			}
			if ("theMrk" == input[0].name) {
				mrk = input[0].value;
			}
			if ("theAmtJPY" == input[0].name) {
				amtJpy = input[0].value;
			}
			if ("theAmtRMB" == input[0].name) {
				amtRmb = input[0].value;
			}
			if ("theAmtSell" == input[0].name) {
				amtSell = input[0].value;
			}
			//...
		}
		var nForm = document.createElement("form");
		document.body.appendChild(nForm);
		nForm.method = 'post';
		nForm.action = '/EggShell/saveItem';

		var itmId = generateHideElement("itmId", e),
		itmNm = generateHideElement("itmNm", nm);
		itmMrk = generateHideElement("itmMrk", mrk);
		itmAmtJPY = generateHideElement("itmAmtJPY", amtJpy);
		itmAmtRMB = generateHideElement("itmAmtRMB", amtRmb);
		itmAMTSell = generateHideElement("itmAmtSell", amtSell);
		
		nForm.appendChild(itmId);
		nForm.appendChild(itmNm);
		nForm.appendChild(itmMrk);
		nForm.appendChild(itmAmtJPY);
		nForm.appendChild(itmAmtRMB);
		nForm.appendChild(itmAMTSell);

		nForm.submit();
		nForm.parentNode.removeChild(nForm);
	}

	function createItem(e) {
		var nm = '';
		var tp = '';
		var mrk = '';
		var amtJpy = '';
		var amtRmb = '';
		var amtSell = '';

		var tr = $("#newItem");
		var tds = [];
		tds = tr[0].getElementsByTagName("td");
		for (var j = 0; j < tds.length - 1; j++) {
			var input = tds[j].getElementsByTagName("input");
			if ("theNm" == input[0].name) {
				nm = input[0].value;
			}
			if ("theMrk" == input[0].name) {
				mrk = input[0].value;
			}
			if ("theAmtJPY" == input[0].name) {
				amtJpy = input[0].value;
			}
			if ("theAmtRMB" == input[0].name) {
				amtRmb = input[0].value;
			}
			if ("theAmtSell" == input[0].name) {
				amtSell = input[0].value;
			}
			//...
		}
		var nForm = document.createElement("form");
		document.body.appendChild(nForm);
		nForm.method = 'post';
		nForm.action = '/EggShell/createItem';

		var itmId = generateHideElement("itmId", ""),
		itmNm = generateHideElement("itmNm", nm);
		itmMrk = generateHideElement("itmMrk", mrk);
		itmAmtJPY = generateHideElement("itmAmtJPY", amtJpy);
		itmAmtRMB = generateHideElement("itmAmtRMB", amtRmb);
		itmAMTSell = generateHideElement("itmAmtSell", amtSell);
		
		nForm.appendChild(itmId);
		nForm.appendChild(itmNm);
		nForm.appendChild(itmMrk);
		nForm.appendChild(itmAmtJPY);
		nForm.appendChild(itmAmtRMB);
		nForm.appendChild(itmAMTSell);

		nForm.submit();
		nForm.parentNode.removeChild(nForm);
	}

	function delItem(e) {
		var nForm = document.createElement("form");
		document.body.appendChild(nForm);
		nForm.method = 'post';
		nForm.action = '/EggShell/delItem';
		var itmId = generateHideElement("itmId", e);
		nForm.appendChild(itmId);
		nForm.submit();
		nForm.parentNode.removeChild(nForm);
	}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>蛋壳跨境电商-货品</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>

<img style="width:50px;height:50px" src="http://oim8ighi5.bkt.clouddn.com/test.jpg">
	<table>
		<tr>
			<th>名字</th>
			<th>备注</th>
			<th>日本价</th>
			<th>RMB价</th>
			<th>出售价</th>
		</tr>
		<c:forEach items="${listEgg}" var="egg">
			<tr id="${egg.itmId}">
				<td><input name="theNm" value="${egg.itmNm}" /></td>
				<td><input name="theMrk" value="${egg.itmMrk}" /></td>
				<td><input name="theAmtJPY" value="${egg.itmAmtJPY}" /></td>
				<td><input name="theAmtRMB" value="${egg.itmAmtRMB}" /></td>
				<td><input name="theAmtSell" value="${egg.itmAmtSell}" /></td>
				<td><button onclick="saveItem('${egg.itmId}')">修改</button></td>
				<td><button onclick="delItem('${egg.itmId}')">删除</button></td>
			</tr>
		</c:forEach>
			<tr id="newItem">
				<td><input name="theNm" value="" /></td>
				<td><input name="theMrk" value="" /></td>
				<td><input name="theAmtJPY" value="" /></td>
				<td><input name="theAmtRMB" value="" /></td>
				<td><input name="theAmtSell" value="" /></td>
				<td><button onclick="createItem()">增加</button></td>
			</tr>
	</table>
</body>
</html>